package com.example.springboot3demo.util;

public class SecurityEncoder {

    private static final String FIXED_A = "RDpbLfCPsJZ7fiv";
    private static final String FIXED_C = "yLwVl0zKqws7LgKPRQ84Mdt708T1qQ3Ha7xv3H7NyU84p21BriUWBU43odz3iP4rBL3cD02KZciXTysVXiV8ngg6vL48rPJyAUw0HurW20xqxv9aYb4M9wK1Ae0wlro510qXeU07kV57fQMc8L6aLgMLwygtc0F10a0Dg70TOoouyFhdysuRMO51yY5ZlOZZLEal1h0t9YQW0Ko7oBwmCAHoic4HYbUyVeU3sfQ1xtXcPcf1aT303wAQhv66qzW";

    public static String securityEncode(String a, String b, String c) {
        StringBuilder e = new StringBuilder();
        int l = 187;
        int n = 187;
        int g = a.length();
        int h = b.length();
        int k = c.length();
        int f = Math.max(g, h);

        for (int p = 0; p < f; p++) {
            n = l = 187;
            if (p >= g) {
                n = b.charAt(p);
            } else if (p >= h) {
                l = a.charAt(p);
            } else {
                l = a.charAt(p);
                n = b.charAt(p);
            }
            int idx = (l ^ n) % k;
            e.append(c.charAt(idx));
        }
        return e.toString();
    }

    public static String orgAuthPwd(String input) {
        return securityEncode(FIXED_A, input, FIXED_C);
    }

    public static void main(String[] args) {
        // 测试用例
        System.out.println(orgAuthPwd("2")); // 应输出: AyWcQbhc9TefbwK
        System.out.println(orgAuthPwd("123456")); // 应输出: 0KcgeXhc9TefbwK
        System.out.println(orgAuthPwd("abc")); // 应输出: W74cQbhc9TefbwK
        System.out.println(orgAuthPwd("18408bWi5q")); // 验证你的目标输入
    }
}